package com.znow.admin.system.security.controller;

import com.znow.admin.dao.entity.sys.SysUserEntity;
import com.znow.admin.system.security.model.res.user.UserRequest;
import com.znow.admin.system.security.model.res.user.UserPageRequest;
import com.znow.admin.system.security.service.SysUserService;
import com.znow.common.model.CommonResult;
import com.znow.common.model.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 *
 * @author Nemo
 * @date 2022/09/30
 */
@Api(value = "user", tags = "用户接口")
@RequestMapping("/sys/user")
@RestController
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "用户列表接口")
    @PostMapping("/list")
    public CommonResult<PageResult<SysUserEntity>> getList(@RequestBody UserPageRequest param) {
        return CommonResult.success(sysUserService.selectByPage(param));
    }

    @ApiOperation(value = "用户详情接口")
    @PostMapping("/get")
    public CommonResult<SysUserEntity> getUser(@RequestBody UserPageRequest param) {
        return CommonResult.success(sysUserService.getUserId(param));
    }

    @ApiOperation(value = "更新用户接口")
    @PostMapping("/update")
    public CommonResult<Boolean> updateUser(@RequestBody UserRequest param) {
        return CommonResult.success(sysUserService.updateUser(param));
    }

    @ApiOperation(value = "添加用户接口")
    @PostMapping("/save")
    public CommonResult<Boolean> saveUser(@RequestBody UserRequest param) {
        return CommonResult.success(sysUserService.saveUser(param));
    }

    @ApiOperation(value = "删除用户接口")
    @PostMapping("/delete")
    public CommonResult<Boolean> deleteUser(@RequestBody UserPageRequest param) {
        return CommonResult.success(sysUserService.deleteUser(param));
    }
}
